﻿<include file="Public/head" />
<body>
<div class="page-container">
	<div class="text-l mt-10">
		<form action="" method="get">
		<span class="select-box inline">
		<select name="type" class="select">
			<option value="" <if condition="$Think.get.type eq 0">selected</if>>全部分类</option>
			<volist name="cate" id="rs">
				<option value="{$key}" <if condition="$Think.get.type eq $key">selected</if>>{$rs}</option>
			</volist>
		</select>
		</span> 日期范围：
		<input type="text" name="start" value="{$Think.get.start}" onfocus="WdatePicker({ maxDate:'#F{ $dp.$D(\'logmax\')||\'%y-%M-%d\'}'})" id="logmin" class="input-text Wdate" style="width:120px;">
		-
		<input type="text" name="end" value="{$Think.get.end}" onfocus="WdatePicker({ minDate:'#F{ $dp.$D(\'logmin\')}',maxDate:'%y-%M-%d'})" id="logmax" class="input-text Wdate" style="width:120px;">
		<input type="text" name="search" value="{$Think.get.search}" placeholder=" 文章名称" style="width:250px" class="input-text">
		<button name="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		</form>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a class="btn btn-primary radius" data-title="添加文章" href="{:U('articleAdd')}"><i class="Hui-iconfont">&#xe600;</i> 添加文章</a></span> </div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="80">ID</th>
					<th>标题</th>
					<th width="80">分类</th>
					<th width="120">更新时间</th>
					<th width="120">创建时间</th>
					<th width="60">创建状态</th>
					<th width="120">操作</th>
				</tr>
			</thead>
			<tbody>
			<volist name="data" id="rs">
				<tr class="text-c">
					<td><input type="checkbox" name="ids[]" value="{$rs['article_id']}"></td>
					<td>{$rs['article_id']}</td>
					<td class="text-l">{$rs['title']}</td>
					<td>{$cate[$rs['type_id']]}</td>
					<td>{$rs['update_time']|date="Y-m-d H:i:s",###}</td>
					<td>{$rs['create_time']|date="Y-m-d H:i:s",###}</td>
					<td class="td-status">
						<if condition="$rs['status'] eq 1">
							<span class="label label-success radius">已发布</span>
							<else />
							<span class="label label-defaunt radius">已下架</span>
						</if>
					</td>
					<td class="f-14 td-manage">
						<if condition="$rs['status'] eq 1">
							<a style="text-decoration:none" onClick="article_stop(this,'{$rs["article_id"]}')" href="javascript:;" title="下架">下架</a>
						    <else />
							<a style="text-decoration:none" onClick="article_start(this,'{$rs["article_id"]}')" href="javascript:;" title="发布">发布</a>
						</if>
						<a style="text-decoration:none" class="ml-5" onClick="article_edit('文章编辑','{:U('articleEdit',array('article_id'=> $rs['article_id']))}','{$rs["article_id"]}')" href="javascript:;" title="编辑">编辑</a>
						<a style="text-decoration:none" class="ml-5" onClick="article_del(this,'{$rs["article_id"]}')" href="javascript:;" title="删除">删除</a>
					</td>
				</tr>

			</volist>
			</tbody>
		</table>
		{$page}
	</div>
</div>
<include file="Public/js" />
<script type="text/javascript">

/*文章-添加*/
function article_add(title,url,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*文章-编辑*/
function article_edit(title,url,id,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*文章-删除*/
function article_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		var load = layer.load();
		$.getJSON('{:U("articleDel")}',{'article_id':id},function(msg){
			layer.close(load);
			if (msg.status == 1){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1});
			}else{
				layer.msg(msg.info);
			}
		})

	});
}
/*文章-审核*/
function article_shenhe(obj,id){
	layer.confirm('审核文章？', {
		btn: ['通过','不通过','取消'], 
		shade: false,
		closeBtn: 0
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="article_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
		$(obj).remove();
		layer.msg('已发布', {icon:6,time:1000});
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="article_shenqing(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">未通过</span>');
		$(obj).remove();
    	layer.msg('未通过', {icon:5,time:1000});
	});	
}
/*文章-下架*/
function article_stop(obj,id){
	layer.confirm('确认要下架吗？',function(index){
		$.getJSON('{:U("changeStatus")}', {'article_id':id,'status':2},function(msg){
			if (msg.status == 1){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_start(this,'+id+')" href="javascript:;" title="发布">发布</a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
				$(obj).remove();
				layer.msg('已下架!',{icon: 5,time:1000});
			}else{
				layer.msg(msg.info);
			}
		})

	});
}

/*文章-发布*/
function article_start(obj,id){
	layer.confirm('确认要发布吗？',function(index){
		$.getJSON('{:U("changeStatus")}', {'article_id':id,'status':1},function(msg){
			if (msg.status == 1){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_stop(this,'+id+')" href="javascript:;" title="下架">下架</a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
				$(obj).remove();
				layer.msg('已发布!',{icon: 6,time:1000});
			}else{
				layer.msg(msg.info);
			}
		})

	});
}
/*文章-申请上线*/
function article_shenqing(obj,id){
	$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
	$(obj).parents("tr").find(".td-manage").html("");
	layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
}
function datadel(){
	var ids = new Array();
	$('input[name="ids[]"]:checked').each(function(i){
		ids[i] = $(this).val();
	});
	if (ids.length == 0){
		layer.msg('请选择文章');
		return false;
	}
	layer.confirm('确认要删除吗？',function(index){
		var load = layer.load();
		$.getJSON('{:U("articleDel")}',{'article_id':ids},function(msg){
			layer.close(load);
			if (msg.status == 1){
				layer.msg('已删除!',{icon:1});
				setTimeout(function(){
					location.reload();
				},500)
			}else{
				layer.msg(msg.info);
			}
		})

	});
}
</script> 
</body>
</html>